const RouterHook = require("../module/routerModule")
const {
    vicinityStationsList,
    StationsDetail,
    StationsOrder,
    StationsPay,
    StationsOverOrder,
    getOrdersStatus
} = require("../service/chargingStations")
const {
    AssertUtils
} = require("../util/utils")
const router = RouterHook()

router.get("/list", async (ctx, netx) => {
    const list = await vicinityStationsList()
    ctx.result.success({
        list
    })
}).noAuth()

router.get("/detail", async (ctx, netx) => {
    const {
        id
    } = ctx.request.query
    AssertUtils.StringNotEmpty(id, "请输入id")
    const data = await StationsDetail(id)
    ctx.result.success(data)
}).noAuth()

router.get("/order", async (ctx, netx) => {
    const {
        carId,
        csId,
        payId
    } = ctx.request.query
    AssertUtils.StringNotEmpty(carId, "请输入汽车编号")
    AssertUtils.StringNotEmpty(csId, "请输入充电桩编号")
    AssertUtils.StringNotEmpty(payId, "请输入金额类型编号")
    const orderId = await StationsOrder(carId, csId, payId, 1)
    ctx.result.success({
        orderId
    })
}).noAuth()

router.get("/over/order", async (ctx, netx) => {
    const {
        csId
    } = ctx.request.query
    AssertUtils.StringNotEmpty(csId, "请输入充电桩编号")
    const orderId = await StationsOverOrder(csId, 1)
    ctx.result.success({}, "订单关闭成功")
}).noAuth()

router.get("/pay", async (ctx, netx) => {
    const {
        orderId,
        payType
    } = ctx.request.query
    AssertUtils.StringNotEmpty(orderId, "请输入订单编号")
    AssertUtils.StringNotEmpty(payType, "请输入支付类型")
    const data = await StationsPay(orderId, payType, 1)
    ctx.result.success(data)
}).noAuth()

router.get('/status', async (ctx, netx) => {
    const {
        status
    } = ctx.request.query
    AssertUtils.StringNotEmpty(status, "请输入订单状态")
    const result = await getOrdersStatus(status)
    ctx.result.success(result)
}).noAuth()

module.exports = router